package com.zyh.util;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class PatternUtil {
    /**
     * 将字符串带@* 变成 <a href='@*'></a>
     * @param s
     * @return
     */
    public static String replace(String s){
        Pattern pattern=Pattern.compile("@\\w+");
        Matcher matcher=pattern.matcher(s);
        while (matcher.find()){
            String str=matcher.group();
            Pattern patterns=Pattern.compile(str);
            Matcher matcher1=patterns.matcher(s);
            s=matcher1.replaceAll("<a href='/"+str.substring(1)+"'>"+str+"</a>");
        }
        return  s;
    }

    public static List<String> findName(String s) {
        List<String> usernameList=new ArrayList<>();
        Pattern pattern=Pattern.compile("@\\w+");
        Matcher matcher=pattern.matcher(s);
        while (matcher.find()){
            usernameList.add(matcher.group());
        }
        return usernameList;
    }

}
